using System;
using System.Collections.Generic;
using System.Text;
using System.Xml.Serialization;
using WozLib.WozObjects;
using WozLib.UI.Ink;

namespace WOzTestUI.WozCommands
{
  class WozScreenChangeNameCommand : WozLib.WozCommands.WozCommand
  {
    [XmlAttribute("ServerID")]
    public long ServerID
    {
      get
      {
        return _ServerID;
      }
      set
      {
        _ServerID = value;
      }
    } long _ServerID;

    [XmlAttribute("PreviousName")]
    public string PreviousName
    {
      get
      {
        return _PreviousName;
      }
      set
      {
        _PreviousName = value;
      }
    } string _PreviousName;

    [XmlAttribute("NewName")]
    public string NewName
    {
      get
      {
        return _NewName;
      }
      set
      {
        _NewName = value;
      }
    } string _NewName;

    public WozScreenChangeNameCommand()
    {
    }

    public WozScreenChangeNameCommand(long serverID, string previousName, string newName)
    {
      ServerID = serverID;
      PreviousName = previousName;
      NewName = newName;
    }

    public override void Undo()
    {
      IServerObject iServerObject = ServerObjectRegistry.GetObject(ServerID);
      if (iServerObject != null && iServerObject is WozScreen)
      {
        (iServerObject as WozScreen).Description = PreviousName;
      }
    }

    public override void Redo()
    {
      IServerObject iServerObject = ServerObjectRegistry.GetObject(ServerID);
      if (iServerObject != null && iServerObject is WozScreen)
      {
        (iServerObject as WozScreen).Description = NewName;
      }
    }
  }
}
